package com.sync;

/**
 *  --不允许2和3重排序
 * 基于volatile的解决方案
 * Created by 峥桂 on 2017/6/6.
 */
public class UnsafeLazyInitiallization04 {
    private volatile static UnsafeLazyInitiallization04 instance;
    private UnsafeLazyInitiallization04() {}

    public static UnsafeLazyInitiallization04 getInstance() {
        if (instance == null) { //4:第一次检查
            synchronized (UnsafeLazyInitiallization04.class) { //5:加锁
                if (instance == null) //6:第二次检查
                    instance = new UnsafeLazyInitiallization04(); //7:问题的根源出在这里
            } //8
        } //9
        return instance; //10

    }
}
